//
//  YZSuggestController.m
//  天气预报
//
//  Created by jacoy on 16/5/7.
//  Copyright © 2016年 jacoy. All rights reserved.
//

#import "YZSuggestController.h"
#import <SVProgressHUD.h>

@interface YZSuggestController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *zishuLabel;//字数限制label
@property (nonatomic,weak)UIButton *cover;
@end

@implementation YZSuggestController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.textView.delegate = self;
    
}
//递交反馈
- (IBAction)dijiaofuikui:(id)sender {
    if (self.textView.text.length == 0) {
        [SVProgressHUD showErrorWithStatus:@"反馈不能为空,请输入内容!"];
    }else if([self.zishuLabel.text integerValue] < 0){

        [SVProgressHUD showErrorWithStatus:@"超过最大字数限制"];
    }else {
        [SVProgressHUD showSuccessWithStatus:@"提交成功"];
    }
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.row == 0) {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否拨打电话" message:@"18326920010" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *destructive = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"打电话");


        UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];

        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://18326920010"]]];


        }];
        [alert addAction:cancel];
        [alert addAction:destructive];
        [self presentViewController:alert animated:YES completion:nil];

    }else{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否与QQ888888对话" message:nil preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *destructive = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"QQ");
        }];
        [alert addAction:cancel];
        [alert addAction:destructive];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
-(void)textViewDidChange:(UITextView *)textView{
    NSLog(@"字数 = %zd",self.textView.text.length);
    NSInteger zishu = 200 - self.textView.text.length;
    self.zishuLabel.text = [NSString stringWithFormat:@"%zd",zishu];
    
    
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    UIButton *cover = [[UIButton alloc]init];
    cover.frame = CGRectMake(0, 220, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    self.cover = cover;
    [self.tableView addSubview:cover];
    [cover addTarget:self action:@selector(coverDidClick:) forControlEvents:UIControlEventTouchDown];

    return YES;
}

-(void)coverDidClick:(UIButton *)button{
    [self.textView endEditing:YES];
    [self.cover removeFromSuperview];
    self.cover = nil;
}
@end
